package top.huntwolf.admin.config;

import com.google.common.base.Predicates;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.ApiKey;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.List;

@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Bean
    public Docket webConfig() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("webAPI")
                .apiInfo(webApiInfo())
                .select()
                .paths(Predicates.not(PathSelectors.regex("/admin/.*")))
                .paths(Predicates.not(PathSelectors.regex("/error.*")))
                .build()
                .securitySchemes(security());

    }

    private ApiInfo webApiInfo() {
        return new ApiInfoBuilder()
                .title("岛上有家书店")
                .description("本文档描述了书店的各个接口")
                .version("1.0.0")
                .contact(new Contact("javaBoyf", "http://javaBoy.com",
                        "1296831731@qq.com"))
                .build();
    }
    private List<ApiKey> security(){
        ApiKey apiKey = new ApiKey("token", "token", "header");
        List<ApiKey> apiKeys = new ArrayList<>();
        apiKeys.add(apiKey);
        ApiKey ak = new ApiKey("yqm-store","yqm-store","header");
        apiKeys.add(ak);
        return apiKeys;
    }

}
